//
//  CZStatus.swift
//  weibo
//
//  Created by Apple on 16/3/15.
//  Copyright © 2016年 KY. All rights reserved.
//

import UIKit

class CZStatus: NSObject {
    
    // 微博id
    var id: Int64 = 0
    
    //  微博内容
    var text: String?
    
    //  发微博的作者信息
    var user: CZUser?
    //  微博发布时间
    var created_at: String?
    //  来源
    var source: String?
    //  转发数
    var reposts_count: Int = 0
    //  评论数
    var comments_count: Int = 0
    //  表态数
    var attitudes_count: Int = 0
    //  转发微博模型
    var retweeted_status: CZStatus?
    
    //  配图数组
    var pic_urls: [CZStatusPictureInfo]?
    
    init(dic: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let userDic = value as? [String: AnyObject] {
                user = CZUser(dic: userDic)
            }
            
        } else if key == "retweeted_status" {
            if let retweeted_statusDic = value as? [String: AnyObject] {
                retweeted_status = CZStatus(dic: retweeted_statusDic)
            }
        } else if key == "pic_urls" {
            
            if let pic_urlsArray = value as? [[String: AnyObject]] {
                var tempArray = [CZStatusPictureInfo]()
                for pic_urlsDic in pic_urlsArray {
                    let pictureInfo = CZStatusPictureInfo(dic: pic_urlsDic)
                    tempArray.append(pictureInfo)
                }
                pic_urls = tempArray
            }
            
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override var description: String {
        let keys = ["text"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
